from selenium import webdriver
import time
from unittest import TestCase

from selenium.webdriver.common.by import By


class Testcal(TestCase):
    def testadmin(self):
        username = "username"
        passwd = "123456"
        expect = "后台管理系统"
        driver = webdriver.Chrome()
        driver.maximize_window()
        driver.get("http://localhost:90/")
        time.sleep(1)


        ele1=driver.find_element(By.ID,"username").send_keys("admin")
        time.sleep(1)
        ele1=driver.find_element(By.ID,"password").send_keys("123456")
        time.sleep(1)
        ele1=driver.find_element(By.ID,"login_btn").click()
        time.sleep(1)
        result = driver.title
        if result != expect:
            driver.save_screenshot(expect + "--.jpg")
        else:
            print("登陆用例通过！")
        driver.quit()
        self.assertEqual(expect,result)


    def testlisi(self):
        username = "username"
        passwd = "123456"
        expect = "个人理财系统"
        driver = webdriver.Chrome()
        driver.maximize_window()
        driver.get("http://localhost:90/")
        time.sleep(1)
        ele1=driver.find_element(By.ID,"username").send_keys("lisi")
        time.sleep(1)
        ele1=driver.find_element(By.ID,"password").send_keys("123456")
        time.sleep(1)
        ele1=driver.find_element(By.ID,"login_btn").click()
        time.sleep(1)
        result = driver.title
        if result != expect:
            driver.save_screenshot(expect + "--.jpg")
        else:
            print("登陆用例通过！")
        driver.quit()
        self.assertEqual(expect,result)



    def testlisi1(self):
        username = "username"
        passwd = "123456"
        expect = "用户名不存在"
        driver = webdriver.Chrome()
        driver.maximize_window()
        driver.get("http://localhost:90/")
        time.sleep(1)
        ele1=driver.find_element(By.ID,"username").send_keys("lisi1")
        time.sleep(1)
        ele1=driver.find_element(By.ID,"password").send_keys("123456")
        time.sleep(1)
        ele1=driver.find_element(By.ID,"login_btn").click()
        time.sleep(1)
        result = driver.find_element(By.XPATH,"/html/body/div/div/div/form/div[1]/span[1]").text
        if result != expect:
            driver.save_screenshot(expect + "--.jpg")
        else:
            print("登陆用例通过！")
        driver.quit()
        self.assertEqual(expect,result)




    def testlisi2(self):
        username = "username"
        passwd = "1234567"
        expect = "密码错误"
        driver = webdriver.Chrome()
        driver.maximize_window()
        driver.get("http://localhost:90/")
        time.sleep(1)
        ele1=driver.find_element(By.ID,"username").send_keys("lisi")
        time.sleep(1)
        ele1=driver.find_element(By.ID,"password").send_keys("1234567")
        time.sleep(1)
        ele1=driver.find_element(By.ID,"login_btn").click()
        time.sleep(1)
        result = driver.find_element(By.XPATH,"/html/body/div/div/div/form/div[2]/span[1]").text
        if result != expect:
            driver.save_screenshot(expect + "--.jpg")
        else:
            print("登陆用例通过！")
        driver.quit()
        self.assertEqual(expect,result)